package leetcode.code1824;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	int len;

	public int minSideJumps(int[] obstacles) {
		this.len = obstacles.length;
		Integer[][] dp = new Integer[len][4];
		return this.minSideJumps(obstacles, 0, 2, dp);
	}

	private int minSideJumps(int[] obstacles, int index, int road, Integer[][] dp) {
		if (obstacles[index] == road) {
			return Integer.MAX_VALUE;
		}
		if (dp[index][road] != null) {
			return dp[index][road];
		}
		int ans = 0;
		for (int i = index; i < len; i++) {
			if (obstacles[i] == road) {
				ans = Integer.MAX_VALUE;
				for (int j = 1; j <= 3; j++) {
					if (j != road) {
						ans = Math.min(this.minSideJumps(obstacles, i - 1, j, dp), ans);
					}
				}
				ans += 1;
				break;
			}
		}
		dp[index][road] = ans;
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(2, this.minSideJumps(H.str2array3("[0,2,1,0,3,0]")));
		H.compare(0, this.minSideJumps(H.str2array3("[0,1,1,3,3,0]")));
		H.compare(2, this.minSideJumps(H.str2array3("[0,1,2,3,0]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
